package com.yc.cloud.security.utils;

import com.yc.cloud.security.dto.AdminUserDetails;
import lombok.val;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @title: AdminUtils
 * @Author JackGu
 * @Date: 2022/11/12 19:15
 * @Version 1.0
 */
public class AdminUtils {

    private static AdminUserDetails getUserDetail() {
        val authentication = SecurityContextHolder.getContext().getAuthentication();
        return (AdminUserDetails) authentication.getPrincipal();
    }

    public static String getCurrentUserName() {
        return getUserDetail().getUsername();
    }

    public static Long getCurrentUseId() {
        return getUserDetail().getUmsAdmin().getId();
    }
}
